1 2 3 4 5
| public static void solve() { String s = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"; int n = io.nextInt(); io.println(s.substring(0, n + 2)); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public static void solve() { int n = io.nextInt(); List<Integer>[] arr = new List[37]; Arrays.setAll(arr, k -> new ArrayList<>()); int[] cnt = new int[n]; for (int i = 0; i < n; i++) { cnt[i] = io.nextInt(); for (int j = 0; j < cnt[i]; j++) { arr[io.nextInt()].add(i); } } int x = io.nextInt(), min = 37; for (int i : arr[x]) min = Math.min(min, cnt[i]); List<Integer> ans = new ArrayList<>(); for (int i : arr[x]) if (cnt[i] == min) ans.add(i); io.println(ans.size()); for (int t : ans) io.print(t + 1 + " "); io.println(); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public static void solve() { int n = io.nextInt(), m = io.nextInt(); char[] s = io.next().toCharArray(); List<Integer>[] arr = new List[m]; Arrays.setAll(arr, k -> new ArrayList<>()); for (int i = 0; i < n; i++) { arr[io.nextInt() - 1].add(i); } for (var v : arr) { if (v.size() == 0) continue; char c = s[v.get(v.size() - 1)]; for (int i = v.size() - 2; i >= 0; i--) { s[v.get(i + 1)] = s[v.get(i)]; } s[v.get(0)] = c; } io.println(new String(s)); }
|
记录时间,每次进行全局操作时将当前时间加一,并记录操作的编号,每次进行局部操作时将对应位置的操作时间更新为当前时间。如果最后某个位置的时间小于当前时间,则需要变换大小写;否则,不需要变换大小写。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public static void solve() { int n = io.nextInt(); char[] s = io.next().toCharArray(); int[] time = new int[n]; int q = io.nextInt(), curTime = 0, flag = 0; while (q-- != 0) { int t = io.nextInt(), x = io.nextInt() - 1; char c = io.next().charAt(0); if (t == 1) { s[x] = c; time[x] = curTime; } else { flag = t; curTime++; } } for (int i = 0; i < n; i++) { if (time[i] < curTime) { if (flag == 2) s[i] = Character.toLowerCase(s[i]); else s[i] = Character.toUpperCase(s[i]); } } io.println(new String(s)); }
|